<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0" id="list" lay-title="个人消费记录">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card hxr-layui-card" id="memberlistv">
                    <div class="layui-form layui-card-header hxradmin-card-header">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style='width:100px;'>消费结束日期范围</label>
                                <div class="layui-input-inline" style="width: 350px;    ">
                                    <input type="text" name="val2" id='date' autocomplete="off" class="layui-input" readonly>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn" data-type="reload" id="search">搜索</button>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn" data-type="excel" id="pexcel">导出数据</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-hide" id="list-select-table" lay-filter="list-select-table"></table>

                    </div>

                </div>
                <!-- <script type="text/html" id="list-select-tableF">
                                <input type="checkbox" name="member_status" lay-skin="switch" lay-text="启用|锁定" lay-filter="list-select-tableF"
                   value="{{ d.member_status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.member_status == 1 ? 'checked' : '' }}>
                </script> -->
            </div>
        </div>
    </div>
</div>
<script>
    var formurl='member/memberform',formarea=['500px', '600px'];
    //表格数据渲染
    layui.use(['table', 'form','laydate'], function() {
        var table = layui.table,
            form = layui.form,
            $ = layui.$,laydate=layui.laydate;
        //日期范围
        laydate.render({
            elem: '#date'
            ,type:'datetime'
            ,done: function(value, date, endDate){
                $('input[name="val2"]').val(value);
                // console.log(value); //得到日期生成的值，如：2017-08-18
                // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                // console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
            ,range: true
        });
        layui.admin.initlist(table,'members/consume_record_list',240,[
            [{
                type: 'checkbox'
            },{
                field: 'consume_record_id',
                title: 'ID',
                width: 60
            },{
                field: 'device_name',
                title: '设备名称',
                width: 100
            },{
                field: 'device_id',
                title: '设备id',
                width: 100
            },{
                field: 'real_name',
                title: '会员姓名',
                width: 100
            },{
                field: 'consume_amount',
                title: '消费总金额(元)',
                width: 110
            },{
                field: 'cash_amount',
                title: '非赠送金额(元)',
                width: 140
            },{
                field: 'credit_amount',
                title: '赠送金额(元)',
                width: 110
            },{
                field: 'valid_time',
                title: '扣费时间',
                width: 150
            },{
                field: 'invalid_time',
                title: '免费时间',
                width: 150
            },{
                field: 'start_time',
                title: '开始时间',
                width: 200
            },{
                field: 'end_time',
                title: '结束时间',
                width: 200
            },{
                field: 'count_time',
                title: '消费总时',
                width: 150
            },
                {
                    field:'agent_name',
                    title:'代理',
                    width:120
                },

                {
                    field: 'agent_income',
                    title: '代理佣金(元)',
                    width: 110
                },{
                field:'income_name',
                title:'分红会员',
                width:120
            },{
                field: 'member_income',
                title: '会员分红(元)',
                width: 110
            },{
                field: 'activity',
                title: '备注',
                width: 200
            }]

        ],'#list-select-table',509);
        //监听表格表单操作
        form.on('switch(list-select-tableF)', function(obj) {
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);
            // json.member_status == 1 ? json.member_status = 2 : json.member_status = 1;
            layui.admin.ajax('members/update_member', json).then((res) => {
                layui.admin.ahint(res.code,res.msg);
                layui.table.reload('list-select-table');
            }).catch((res) => {});
        });

        //监听行双击事件
        /* table.on('rowDouble(list-select-table)', function(obj) {
            //查看详情
            layui.admin.pupF('详情', formarea, formurl, 3, obj.data);
        }); */
        var active = {
            //多行删除
            batchdel: function() {
                layui.admin.delsF(table,'members/delete','member_id');
            }
            //添加
            // 	,
            // add: function(othis) {
            // 	layui.admin.pupF('添加', formarea, formurl, 1, {})
            // }
        };
        //操作dom
        $('.layui-btn.layuiadmin-btn-list').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //搜索
        $('#search').on('click', function() {
            var val1 = $('input[name="user"]'),
                val2 = $('input[name="val2"]').val();
            if (val2){
                var datemin=val2.split(' - ')[0],datemax=val2.split(' - ')[1];
            }else{
                var datemin='',datemax='';
            }
            console.log($('input[name="val2"]').val())
            //执行重载
            table.reload('list-select-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    search_text: val1.val(),
                    datemin:datemin,
                    datemax:datemax
                }
            });
        });
        //导出
        $('#pexcel').on('click', function() {
            var val1 = $('input[name="user"]'),
                val2 = $('input[name="val2"]').val();
            if (val2){
                var datemin=val2.split(' - ')[0],datemax=val2.split(' - ')[1];
            }else{
                var datemin='',datemax='';
            }
            layui.admin.excel(table,'members/consume_record_list',
                {
                    search_text: val1.val(),
                    datemin:datemin,
                    datemax:datemax
                },'');
        });
    });
</script>
